package com.zxy.ziems.server.device.pojo.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zxy.btp.common.util.JsonUtils;
import com.zxy.ziems.server.device.pojo.entity.ChannelDeviceEntity;
import com.zxy.ziems.server.device.pojo.entity.DeviceEntity;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Null;
import lombok.Data;

import java.util.Objects;

/**
 * 通道关联设备 配置请求
 * @author 10348359
 * @create 2024-03-25 19:07
 */
@Data
public class ChannelDeviceDTO<T> {
    /**
     * 设备ID
     */
    @Null(message = "ID必须为空", groups = {Add.class})
    @NotBlank(message = "ID不能为空", groups = {Update.class, Delete.class})
    private String id;

    /**
     * 设备ID
     */
    @NotBlank(message = "设备ID不能为空", groups = {Add.class, Update.class})
    private String deviceId;

    /**
     * 通信通道ID
     */
    @NotBlank(message = "通信信道不能为空", groups = {Add.class, Update.class})
    private String channelId;

    /**
     * 品牌
     */
    private String brand;

    /**
     * 型号
     */
    private String model;

    /**
     * 高级配置信息，比如 modbus配置的从站号 {"station": 1}
     */
    private T advanced;

    @JsonIgnore
    public ChannelDeviceEntity buildEntity() {
        ChannelDeviceEntity entity = new ChannelDeviceEntity();
        entity.setId(id);
        entity.setDeviceId(deviceId);
        entity.setChannelId(channelId);
        return entity;
    }

    public interface Add{}
    public interface Update{}
    public interface Delete {}
}
